﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Workflow
//  File name:	WH.cs
//  Developer:	Solomatov Igor
//  Created:	16.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using Smart.Common;

namespace Smart.Workflow
{
	public static class WH
	{
		/// <summary>
		/// Returns Task Status "Completed" value 
		/// </summary>
		public static string GetTaskStatusCompleted()
		{
			return SPUtility.GetLocalizedString("$Resources:core,Tasks_Completed;", "Core", Workflow.GetLang());
		}

		/// <summary>
		/// Returns Task Status value 
		/// </summary>
		public static string GetTaskStatus(SPWorkflowTaskProperties properties)
		{
			try
			{
				return properties.ExtendedProperties[SPBuiltInFieldId.TaskStatus].SToStr(null);
			}
			catch
			{
				return null;
			}
		}

		/// <summary>
		/// Checks whether task is completed
		/// </summary>
		public static bool IsTaskCompleted(SPWorkflowTaskProperties properties)
		{
			try
			{
				if (GetTaskStatusCompleted().EqIC(GetTaskStatus(properties)))
					return true;

				if (Math.Abs(properties.PercentComplete - 1.0) < 0.0001)
					return true;
			}
			catch (Exception x)
			{
				H.LX("WH.IsTaskCompleted", x);
			}

			return false;
		}
	}
}